home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLOBSH.PAK / LDATE.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  162 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  LDATE.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __LDATE_H )
  11. #define __LDATE_H
  12.  
  13. #define BI_OLDNAMES
  14.  
  15. #if !defined( __DOS_H )
  16. #include <Dos.h>
  17. #endif  // __DOS_H
  18.  
  19. #if !defined( __CHECKS_H )
  20. #include <checks.h>
  21. #endif  // __CHECKS_H
  22.  
  23. #if !defined( __SORTABLE_H )
  24. #include "classlib\obsolete\Sortable.h"
  25. #endif  // __SORTABLE_H
  26.  
  27. #pragma option -Vo-
  28. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  29. #pragma option -po-
  30. #endif
  31.  
  32. _CLASSDEF(ostream)
  33. _CLASSDEF(BaseDate)
  34. _CLASSDEF(Date)
  35.  
  36. class _CLASSTYPE BaseDate : public Sortable
  37. {
  38.  
  39. public:
  40.  
  41.     unsigned Month() const;
  42.     unsigned Day() const;
  43.     unsigned Year() const;
  44.     void SetMonth( unsigned _TCHAR );
  45.     void SetDay( unsigned _TCHAR );
  46.     void SetYear( unsigned );
  47.  
  48.     virtual hashValueType hashValue() const;
  49.     virtual int isEqual( const Object _FAR & ) const;
  50.     virtual int isLessThan( const Object _FAR & ) const;
  51.     virtual void printOn( ostream _FAR & ) const = 0;
  52.  
  53. protected:
  54.  
  55.     BaseDate();
  56.     BaseDate( unsigned _TCHAR, unsigned _TCHAR, unsigned );
  57.     BaseDate( const BaseDate _FAR & );
  58.  
  59. private:
  60.  
  61.     unsigned _TCHAR MM;
  62.     unsigned _TCHAR DD;
  63.     unsigned int YY;
  64.  
  65. };
  66.  
  67. inline BaseDate::BaseDate()
  68. {
  69.     struct date d;
  70.     getdate( &d );
  71.     MM = d.da_mon;
  72.     DD = d.da_day;
  73.     YY = d.da_year;
  74. }
  75.  
  76. inline BaseDate::BaseDate( unsigned _TCHAR M, unsigned _TCHAR D, unsigned Y )
  77. {
  78.     SetMonth( M );
  79.     SetDay( D );
  80.     SetYear( Y );
  81. }
  82.  
  83. inline BaseDate::BaseDate( const BaseDate _FAR & B ) :
  84.     MM(B.MM), DD(B.DD), YY(B.YY)
  85. {
  86. }
  87.  
  88. inline unsigned BaseDate::Month() const
  89. {
  90.     return MM;
  91. }
  92.  
  93. inline unsigned BaseDate::Day() const
  94. {
  95.     return DD;
  96. }
  97.  
  98. inline unsigned BaseDate::Year() const
  99. {
  100.     return YY;
  101. }
  102.  
  103. inline void BaseDate::SetMonth( unsigned _TCHAR M )
  104. {
  105.     PRECONDITION( M > 0 && M < 13 );
  106.     MM = M;
  107. }
  108.  
  109. inline void BaseDate::SetDay( unsigned _TCHAR D )
  110. {
  111.     PRECONDITION( D < 32 );
  112.     DD = D;
  113. }
  114.  
  115. inline void BaseDate::SetYear( unsigned Y )
  116. {
  117.     YY = Y;
  118. }
  119.  
  120. class _CLASSTYPE Date : public BaseDate
  121. {
  122.  
  123. public:
  124.  
  125.     Date();
  126.     Date( unsigned _TCHAR, unsigned _TCHAR, unsigned );
  127.     Date( const Date _FAR & );
  128.  
  129.     virtual classType isA() const
  130.         {
  131.         return dateClass;
  132.         }
  133.  
  134.     virtual _TCHAR _FAR *nameOf() const
  135.         {
  136.         return "Date";
  137.         }
  138.  
  139.     virtual void printOn( ostream _FAR & ) const;
  140.  
  141. };
  142.  
  143. inline Date::Date()
  144. {
  145. }
  146.  
  147. inline Date::Date( unsigned _TCHAR M, unsigned _TCHAR D, unsigned Y ) :
  148.     BaseDate( M, D, Y )
  149. {
  150. }
  151.  
  152. inline Date::Date( const Date& D ) : BaseDate( D )
  153. {
  154. }
  155.  
  156. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  157. #pragma option -po.
  158. #endif
  159. #pragma option -Vo.
  160.  
  161. #endif  // __LDATE_H
  162.